<?php
// +----------------------------------------------------------------------
// | Fanwe 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: awfigq(awfigq@qq.com)
// +----------------------------------------------------------------------

//供应商家
class SuppliersModel extends CommonModel {
	public function createSuppliers($goodsID,$endTime)
	{
		D("Suppliers")->where("goods_id = $goodsID")->delete();
		foreach($_REQUEST['suppliers_name'] as $key=>$suppliersName)
		{
			if(!empty($suppliersName))
			{
				$longitude = floatval($_REQUEST['suppliers_longitude'][$key]);
				$latitude = floatval($_REQUEST['suppliers_latitude'][$key]);
				
				if(abs($longitude) > 0 && abs($latitude) > 0)
				{
					$suppliers['goods_id'] = $goodsID;
					$suppliers['name'] = $suppliersName;
					$suppliers['address'] = $_REQUEST['suppliers_address'][$key];
					$suppliers['map_address'] = $_REQUEST['suppliers_map_address'][$key];
					$suppliers['tel'] = $_REQUEST['suppliers_tel'][$key];
					$suppliers['desc'] = $_REQUEST['suppliers_desc'][$key];
					$suppliers['longitude'] = round($longitude,6);
					$suppliers['latitude'] = round($latitude,6);
					$suppliers['end_time'] = $endTime;
					D("Suppliers")->add($suppliers);
				}
				
			}
		}
	}
	
	public function deleteSuppliers($ids)
	{
		$condition = array ('goods_id' => array ('in',$ids));
		D("Suppliers")->where($condition)->delete();
	}
	
	public function getSuppliers($goodsID)
	{
		return D("Suppliers")->where("goods_id = $goodsID")->findAll();
	}
}
?>